package com.zhang.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhang.goods.entity.ProductAttrValue;
import com.zhang.goods.mapper.ProductAttrValueMapper;
import com.zhang.goods.service.IProductAttrValueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品的属性值表 服务实现类
 * </p>
 *
 * @author 创世神
 * @since 2023-10-04
 */
@Service
public class ProductAttrValueServiceImpl extends ServiceImpl<ProductAttrValueMapper, ProductAttrValue> implements IProductAttrValueService {

    @Override
    public List<ProductAttrValue> listBySpuId(Long spuId) {
        QueryWrapper<ProductAttrValue> wrapper = new QueryWrapper<>();
        wrapper.eq("spu_id",spuId);
        return this.list(wrapper);
    }

    @Override
    public ProductAttrValue getByAttrIdAndSpuId(Long attrId,Long spuId) {
        LambdaQueryWrapper<ProductAttrValue> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductAttrValue::getAttrId,attrId);
        wrapper.eq(ProductAttrValue::getSpuId,spuId);
        ProductAttrValue one = getOne(wrapper);
        return one;
    }
}
